﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows;
using System.Diagnostics;
using System.Collections.ObjectModel;

namespace MedicalInterface.ViewModel
{
    public class AddPrescViewModel : BaseViewModel
    {
        #region variables
        private bool _closeSignal;
        private PatientServiceReference.Observation _obs;  //observation for view
        private ObservationServiceReference.Observation _obs2;  //observation for database
        private ObservableCollection<string> _prescriptions;
        private string _prescription;

        #endregion

        #region commandes
        private ICommand _cmd_ok;
        #endregion



        #region getter / setter
        /// <summary>
        /// command pour OK
        /// </summary>
        public ICommand cmd_ok
        {
            get
            {
                if (_cmd_ok == null)
                {
                    _cmd_ok = new RelayCommand(Confirm, CanOk);
                }
                return _cmd_ok;
            }
            set { _cmd_ok = value; }
        }
        /// <summary>
        /// indique si on doit fermer la fenêtre ou non
        /// </summary>
        public bool CloseSignal
        {
            get { return _closeSignal; }
            set
            {
                if (_closeSignal != value)
                {
                    _closeSignal = value;
                    OnPropertyChanged("CloseSignal");
                }
            }
        }


        /// <summary>
        /// Prescription du patient
        /// </summary>
        public string Prescription
        {
            get { return _prescription; }
            set { _prescription = value; }
        }
        #endregion


        /// <summary>
        /// constructeur
        /// </summary>
        public AddPrescViewModel(   ref PatientServiceReference.Observation obs, 
                                    ref ObservationServiceReference.Observation obs2,
                                    ref ObservableCollection<string> prescriptions)
        {
            _obs = obs;
            _obs2 = obs2;
            _prescriptions = prescriptions; //Used for the addObs windows
        }



        /// <summary>
        /// Le bouton OK est-il accessible?
        /// </summary>
        /// <param name="parameter">Type Object</param>
        /// <returns>True</returns>
        private bool CanOk(object parameter)
        {
            return true;
        }

        /// <summary>
        /// Valider l'ajout d'une prescription
        /// </summary>
        private void Confirm(object parameter)
        {
            List<String> prescs = null;
            if(_obs.Prescription != null && _obs.Prescription.Length > 0)
                prescs = new List<string>(_obs.Prescription);
            else
                prescs = new List<string>();
            if (Prescription != null)
            {
                prescs.Add(Prescription);
                _prescriptions.Add(Prescription);
            }
            _obs.Prescription = prescs.ToArray();
            _obs2.Prescription = prescs.ToArray();
            CloseSignal = true;
        }        


    }
}
